package com.swy.task;

import com.swy.service.SensitiveWordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 缓存清理定时任务
 */
@Component
public class CacheCleanupTask {
    private static final Logger logger = LoggerFactory.getLogger(CacheCleanupTask.class);
    
    @Autowired
    private SensitiveWordService sensitiveWordService;
    
    /**
     * 定时任务方法 - 每小时整点执行
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void scheduledCleanup() {
        logger.info("开始执行定时清理任务");
        try {
            sensitiveWordService.cleanCache();
            logger.info("定时清理任务执行成功");
        } catch (Exception e) {
            logger.error("定时清理任务执行失败", e);
        }
    }
} 